package com.fupan.Controller;

import org.springframework.amqp.rabbit.core.RabbitTemplate;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.Date;

@Controller
@RequestMapping("/mq")
public class MqController {

    @Autowired
    RabbitTemplate rabbitTemplate;


    @RequestMapping("trigger")
    @ResponseBody
    public String trigger(Integer operationsType) {

        System.out.println(operationsType);
        Date currentDate = new Date();
        String msg = "";

        //根据不同的操作类型,做不同的处理
        if (operationsType == 1) {
            msg = "SimpleMsg " + currentDate;
            //生产者发送消息
            rabbitTemplate.convertAndSend("", "simpleQueue", msg);
            System.out.println(msg);
        } else if (operationsType == 2) {
            msg = "WorksMsg " + currentDate;
            //生产者发送消息
            rabbitTemplate.convertAndSend("", "worksQueue", msg);
            System.out.println(msg);
        } else if (operationsType == 3) {
            msg = "FanoutExchangeMsg " + currentDate;
            //生产者发送消息
            rabbitTemplate.convertAndSend("fanoutExchange", "", msg);
            System.out.println(msg);
        } else if (operationsType == 4) {
            msg = "directExchange add " + currentDate;
            rabbitTemplate.convertAndSend("directExchange", "add", msg);
            System.out.println(msg);

            msg = "directExchange delete " + currentDate;
            rabbitTemplate.convertAndSend("directExchange", "delete", msg);
            System.out.println(msg);

            msg = "directExchange update " + currentDate;
            rabbitTemplate.convertAndSend("directExchange", "update", msg);
            System.out.println(msg);

            msg = "directExchange query " + currentDate;
            rabbitTemplate.convertAndSend("directExchange", "query", msg);
            System.out.println(msg);
        } else if (operationsType == 5) {

            msg = "topicExchange big.fish " + currentDate;
            rabbitTemplate.convertAndSend("topicExchange", "big.fish", msg);
            System.out.println(msg);


            msg = "topicExchange big.cat.blue " + currentDate;
            rabbitTemplate.convertAndSend("topicExchange", "big.cat.blue", msg);
            System.out.println(msg);


            msg = "topicExchange small.cat.blue " + currentDate;
            rabbitTemplate.convertAndSend("topicExchange", "small.cat.blue", msg);
            System.out.println(msg);

        }else if (operationsType == 6) {

            msg = "normalExchange " + currentDate;
            rabbitTemplate.convertAndSend("normalExchange", "DeadLetter", msg);
            System.out.println(msg);

//            msg = "deadLetterExchange " + currentDate;
//            rabbitTemplate.convertAndSend("deadLetterExchange", "", msg);
//            System.out.println(msg);



        }


        return "ok";
    }
}